let title = "";
function render(title) {
  $.ajax({
    method: "get",
    data: {
      title,
    },
    url: "/goods",
    success(res) {
      // console.log(res);
      let arr = res.data.list.map(function (item) {
        return `<li>
        <img src="${item.img}" alt="" />
        <h3>${item.title}</h3>
        <p>
          <span>${item.price}</span>
          <span>+</span>
        </p>
      </li>`;
      });
      $(".good-list ul").html(arr.join(""));
    },
  });
}
render(title);

const arr1 = [];
$("input").on("keyup", function (e) {
  if (!$(this).val().trim()) {
    return alert("请输入内容");
  }
  if (e.key === "Enter") {
    arr1.push($(this).val());
    render($(this).val());
    let str3 = arr1.map(function (item) {
      return `<li>${item}</li>`;
    });
    $(".history-list ul").html(str3.join(""));
  }
});
$("h3 span").click(function () {
  $(".history-list ul").html("");
});
